<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="spring" 	uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" 	uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c"		uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" 	uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" pageEncoding="utf-8"%>

<script type="text/javascript">

$(document).ready(function(){
	setMenuSelection("clienti");
	
    $("#tabParteneriCard").kendoTabStrip({
        animation:  {
            open: {
                effects: "fadeIn"
            }
        }
    });	  
    
    
    $("#btParteneriList").kendoButton({
        icon: "funnel"
    });

    $("#btParteneriCard").kendoButton({
        icon: "plus"
    });
    
    $("#btParteneriCardSubmit").kendoButton({
        icon: "tick"
    });

    $("#btParteneriCardReset").kendoButton({
        icon: "cancel"
    });
    
    $("#btParteneriCardApply").kendoButton({
        icon: "custom"
    });
    
    //  Set property Date
    for (var i=0;i<20;i++){
    	$("#pAss"+i).kendoDatePicker({
         	 format: "dd.MM.yyyy"
         });
    	$("#pAss"+i).attr("readonly", "readonly");
    	$("#pAssT"+i).kendoDropDownList();
    }
    
    validator = $("#formParteneriCard").kendoValidator().data("kendoValidator");
    status = 	$(".status");
    
    
});


function SubmitFormParteneriCard(pPostOperation){

	 if (validator.validate()) {
		 console.log("Form Is OK");
		//$("#formCompaniesCard").submit();
		var formAction = $("#formParteneriCard").attr( 'action' );
		$("#formParteneriCard").attr('action', formAction + '?pPostOperation='+pPostOperation);
		$("#formParteneriCard").submit();
		
	 } else {
   	 console.log("Form Is BAD");
		 $("#validationErrorMessageParteneriCard").text("Nu sunt completate toate cimpurile! Verificati!");
	 }
}

function addRowToTable() {
	var table = document.getElementById("assTable");
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	var cell1 = row.insertCell(0);
	var cell2 = row.insertCell(1);
	var cell3 = row.insertCell(2);
	cell1.innerHTML = "Data expirării:";
	rowCount=rowCount-1;
	cell2.innerHTML =  		'<input id="pp'+rowCount+'.id"  name="regPartnersAss'+rowCount+'.id"  type="hidden"/>'+ 
		 					'<input id="pAss'+rowCount+'" name="regPartnersAss['+rowCount+'].expirationDate" style="width:150px;"  />' ;
	cell3.innerHTML = '	<select id="pAssT'+rowCount+'" name="regPartnersAss['+rowCount+'].refAssType.id" style="width: 100px; display: none;" data-role="dropdownlist"><option value="1" selected="selected">RCA</option><option value="2">CASCO</option><option value="3">BUNURI</option></select>'
		 					
	$("#pAss"+rowCount).kendoDatePicker({
    	 format: "dd.MM.yyyy"
    });	
	$("#pAssT"+rowCount).kendoDropDownList();
		 
}

function delRowFromTable(){
	var table = document.getElementById("assTable");
	var rowCount = table.rows.length;
	table.deleteRow(rowCount-1);
}
</script>

<CENTER>
<p style="text-align: left;">
	<button id="btParteneriList" type="button" onclick="javascript:window.open('vizualizeazaParteneri', target='_self')";>Lista partenerilor</button>
	<button id="btParteneriCard" type="button" onclick="javascript:window.open('adaugaParteneri', 		target='_self')";>Adaugă partener</button>
	<c:if test="${errorMessage != '' &&  errorMessage != '0'}">
		<span id="errorMessage" class="errorMessage"> ${errorMessage} </span>
	</c:if>
	
</p>
<form:form id="formParteneriCard" method="post" commandName="parteneriItem" action="adaugaParteneri">
<div id="tabParteneriCard" style="text-align: left;" >
	<ul>
	    <li class="k-state-active">
	              Partener
	    </li>
	    	     <li>
	              Asigurari
	    </li>
	</ul> 
	<div>
		<div class="k-block k-shadow">
			<ul class="forms" style="font-size: 14px;">
				<form:hidden id="pId" path="id" name="id"/>
				<li>
					<label  for="pIdno" class="required">Cod fiscal: </label> 			
					<form:input type="text" id="pIdnp" 	 				path="idno"  				name="idno" 	maxlength="13" style="width:150px;" class="k-textbox" required="true"/> 
				</li><li>
					<label  for="pCompanyName" class="required">Denumire firmă: </label> 
					<form:input type="text" id="pCompanyName" 			path="companyName"  		name="companyName" style="width:250px;"  class="k-textbox"  required="true"/>
				</li>
				<li>
					<label  for="pFirstName" >Nume, Prenume director: </label>
					<form:input type="text" id="pBossNameSurname" 	path="bossNameSurname" 	name="bossNameSurname" style="width:250px;"  class="k-textbox"/>
				</li>
				<li>							
					<label  for="pAddress" >Adresa:  </label> 			
					<form:textarea  type="text" id="pAddress" 			path="address"  			name="address" style="width:250px;"  class="k-textbox"></form:textarea> 
				</li><li>							
					<label  for="pAddress" >Adresa juridică:  </label> 	
					<form:textarea  type="text" id="pJuridicAddress" 	path="juridicAddress"  		name="juridicAddress" style="width:250px;"  class="k-textbox"></form:textarea> 
				</li><li>					
					<label  for="pPhoneMob" >Tel. mobil:  </label> 						
					<form:input type="text" id="pPhoneMob" 				path="phoneMob"  			name="phoneMob" 	style="width:150px;"  class="k-textbox"  />										
				</li><li>
					<label  for="pPhoneServ" >Tel. serviciu:  </label> 					
					<form:input type="text" id="pPhoneServ" 			path="phoneServ"  			name="phoneServ" 	style="width:150px;"  class="k-textbox"  />
				</li><li>							
					<label  for="pSkype" >Messenger:  </label> 							
					<form:input type="text" id="pSkype" 				path="skype"  				name="skype" 		style="width:150px;"  class="k-textbox"  /> 
				</li><li>							
					<label  for="pEmal" >E-mail:  </label> 								
					<form:input type="text" id="pEmal" 					path="emal"  				name="emal" 		style="width:150px;"  class="k-textbox"  /> 
				</li><li>							
					<label  for="pCompanySite"> Site:  </label>							
					<form:input type="text" id="pCompanySite" 			path="companySite"  		name="companySite" 		style="width:150px;"  class="k-textbox"  /> 
				</li><li>							
					<label  for="pGoodsServices"> Bunuri/Servicii:  </label>							
					<form:input type="text" id="pGoodsServices" 			path="goodsServices"  		name="goodsServices" 		style="width:250px;"  class="k-textbox"  /> 
				</li>
				<li>							
					<label  for="pProcent" class="required"> Procentul (%):  </label>							
					<form:input type="text" id="pProcent" 			path="procent"  		name="procent" 		style="width:50px;"  class="k-textbox" required="true" /> 
				</li>
			</ul>	
		</div>
	</div>
	
	<div>
		<div class="k-block k-shadow">
			<ul class="forms" style="font-size: 14px;">
					<table id=assTable>
						    <tr>
						        <th align="right">Asigurari:</th>
						    </tr>
						    <c:forEach items="${parteneriItem.regPartnersAss}" var="pp" varStatus="status1">
						        <tr>
					            
						            <td>
						            	<label  for="pp${status1.index}.value">Data expirării:</label>
						            </td> 
						            <td>
						            	<form:hidden id="pp${status1.index}.id" path="regPartnersAss[${status1.index}].id" name="pp${status1.index}.id"/> 
									 	<form:input  id="pAss${status1.index}"   path="regPartnersAss[${status1.index}].expirationDate" style="width:150px;"  /> 
									 </td>
									 <td>
									 	<form:select id="pAssT${status1.index}"   path="regPartnersAss[${status1.index}].refAssType.id" style="width:100px;" >
	     								<form:options items="${refAssTypeCBX}" itemValue="id" itemLabel="mdValue"/>
	   									</form:select>	
									 </td>
						        </tr>
						    </c:forEach>
						</table>
					
					<button id="btAdd"		type="button" onclick="addRowToTable();" 	>Adaugă</button>
					<button id="btDel"		type="button" onclick="delRowFromTable();" 	>Elimina</button>
				</ul>
		</div>		
	</div>	
	
	
</div>
<p style="text-align: right;">
	<span id="validationErrorMessageParteneriCard" class="status" style="color: red; float: left;"></span>
	<button id="btParteneriCardApply"		type="button" 	onclick="SubmitFormParteneriCard('remain')" 	>Aplică</button>
	<button id="btParteneriCardSubmit" 	type="button" 		onclick="SubmitFormParteneriCard('close')"  >Salvează</button>
	<button id="btParteneriCardReset" 	type="reset"  		onclick="javascript: window.history.back();">Anulează</button>
</p> 
</form:form> 
    
    
</CENTER>
<style scoped>
     #formParteneriCard ul {
         list-style-type: none;
         margin: 0;
         padding: 0;
     }
     #formParteneriCard li {
         margin: 10px 0 0 0;
     }

     label {
         display: inline-block;
         width: 300px;
         text-align: right;
     }
     
     input {
     	height: 10px;
     }

     .required {
         font-weight: bold;
     }

     .accept, .status {
         padding-left: 90px;
     }

     .valid {
         color: green;
     }

     .invalid {
         color: red;
     }
     span.k-tooltip {
         margin-left: 6px;
     }
 </style>



